// 处理权限路由逻辑
import { asyncRoutes, constantRoutes } from '@/router/index'
const state = {
  routerList: [] // 左侧菜单列表
}
const mutations = {
  setRouterList(state, list) {
    // 静态动态路由结合在一起赋值
    state.routerList = [...constantRoutes, ...list]
  }
}
const actions = {
  permissRouter({ commit }, menus) {
    // 根据用户的权限列表(调用时传进来)
    // 动态路由的数组
    // 一起筛选的出有权限的路由列表
    const routes = asyncRoutes.filter(item => menus.includes(item.name))
    // console.log(routes)
    // console.log(menus)
    commit('setRouterList', routes)
    return routes
  }
}

export default {
  // 命名空间
  namespaced: true,
  state,
  mutations,
  actions
}
